package com.fingard.dsp.bank.directbank.cmb06.util;

import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.SignatureGenerationException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import org.bouncycastle.util.encoders.Hex;

/**
 * @program: ybyy-policy->AlgorithmExtend
 * @description:
 * @author: ex_lanyixin
 * @create: 2020-05-15 16:05
 **/
public class SM3withSM2Algorithm extends Algorithm {

    private final String privateKey;

    protected SM3withSM2Algorithm(String name, String description, String privateKey) {
        super(name, description);
        this.privateKey = privateKey;
    }

    @Override
    public void verify(byte[] bytes, byte[] bytes1) throws SignatureVerificationException {

    }

    @Override
    public byte[] sign(byte[] bytes) throws SignatureGenerationException {
        byte[] sign = null;
        try {
            sign = SM2Util.hexToByte(Hex.toHexString(SM2Util.sm3withsm2Signature2(privateKey, new String(bytes))));
        } catch (Exception e) {
            new SignatureGenerationException(this,e);
        }
        return sign;
    }
}
